<?php

namespace Tiger\Api\Utils;
class InputWrapper
{

    //数组成员变量
    private $InputWrapperContainer=[];

    //构造函数
    function __construct($request,$attributes)
    {
        foreach($attributes as $attribute)
        {
            $this->InputWrapperContainer[$attribute]=$request->input($attribute);
        }
    }


    /**
     * Dynamically retrieve attributes on the model.
     *
     * @param  string  $key
     * @return mixed
     */
    public function __get($key)
    {
        return $this->getAttribute($key);
    }

    /**
     * Dynamically set attributes on the model.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return void
     */
    public function __set($key, $value)
    {
        $this->setAttribute($key, $value);
    }


    /**
     * Determine if an attribute exists on the model.
     *
     * @param  string  $key
     * @return bool
     */
    public function __isset($key)
    {
        return (isset($this->InputWrapperContainer[$key])&&!is_null($this->getAttributeValue($key)));
    }

    /**
     * Unset an attribute on the model.
     *
     * @param  string  $key
     * @return void
     */
    public function __unset($key)
    {
        unset($this->InputWrapperContainer[$key]);
    }


    /**
     * Get an attribute from the model.
     *
     * @param  string  $key
     * @return mixed
     */
    public function getAttribute($key)
    {
        if (array_key_exists($key, $this->InputWrapperContainer)) {
                return $this->InputWrapperContainer[$key];

        }
        return null;
    }


    /**
     * Set a given attribute on the model.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return $this
     */
    public function setAttribute($key, $value)//设置属性
    {
        $this->InputWrapperContainer[$key] = $value;
        return $this;
    }


    /**
     * Set a given attribute on the model.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return $this
     */
    public function all()//设置属性
    {
     return $this->InputWrapperContainer;
    }



    /**
     * Get all attribute on the model.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return $this
     */
    public function has($key)//设置属性
    {
      return  isset($this->InputWrapperContainer[$key]);
    }


}